package bstsetcode.stanforduniversity18;

/**
 * @author noob
 * @version 1.0
 * @date 2021/3/15 22:23
 * 递归反转一个链表
 */
public class RecursiveReverse {

    public static ListNode reverse(ListNode head){
        if(head == null || head.next == null){
            return head;
        }

        ListNode newHead = reverse(head.next);
        head.next.next=head;
        head.next=null;

        return newHead;
    }


    public static void main(String[] args) {
        int[] nums3 = {5,6,7,8,9};
        ListNode headA = new ListNode(nums3);
        ListNode reverse = RecursiveReverse.reverse(headA);
        System.out.println(reverse);
    }
}
